package com.itheima.controller;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @PostMapping("/upload.do")
    public Result upload(MultipartFile imgFile) throws IOException {
        return setmealService.upload(imgFile);
    }

    @PostMapping("/add.do")
    public Result add(@RequestBody Setmeal setmeal,Integer [] checkgroupIds){
        return setmealService.add(setmeal,checkgroupIds);
    }

    @PostMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return setmealService.findPage(queryPageBean);
    }

    @GetMapping("/findById.do")
    public Result findById(Integer id){
        return setmealService.findById(id);
    }

    @PutMapping("/edit.do")
    public Result edit(Integer [] checkgroupIds,@RequestBody Setmeal setmeal){
        return setmealService.edit(checkgroupIds,setmeal);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        return setmealService.delete(id);
    }
}
